package ${ApiPackage};

import com.askj.integration.application.ApplicationSupport;
import ${CreateCommandPackage}.${CreateCommandClassName};
import ${ApplicationPackage}.${entity}Application;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.askj.integration.encrypt.annotation.AesResponseEncrypt;
import com.askj.integration.encrypt.support.AesEncryptApiResponseFallback;
import com.askj.integration.infrastructure.support.PageResult;
import com.askj.integration.interfaces.AbstractControl;
import com.askj.integration.security.response.ResponseResultBody;
import com.askj.modules.config.BaseUserInfo;
import org.springframework.web.bind.annotation.*;
import com.askj.integration.security.response.ResponseType;
import com.askj.integration.security.response.SystemResponse;
import com.askj.integration.encrypt.annotation.AesDecrypt;
import com.askj.integration.limiting.annotation.RateLimiter;
import java.util.List;


/**
 * ${table.comment!} API
 * @author ${author}
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping
@Api(tags = "APP-${table.comment!}-接口")
public class ${entity}Api extends AbstractControl {

    private final ${entity}Application application;

    @ApiOperation("新增${table.comment!}")
    @ResponseResultBody(type = ResponseType.INTEGER, responseClass = SystemResponse.class)
    @PostMapping(value = {"/v1//create"})
    @AesDecrypt
    @AesResponseEncrypt(fallbackFactory = AesEncryptApiResponseFallback.class)
    @RateLimiter(name = "${table.name}",   interval= 1000, fallbackFactory = ${Entity}RateLimiterFallback.class)
    public String create(@Validated @RequestBody ${CreateCommandClassName} command) {
        return application.save(command);
    }

    /**
     * 查询
     * @return
     */
    @ApiOperation(value = "查询${table.comment!}")
    @AesResponseEncrypt(fallbackFactory = AesEncryptApiResponseFallback.class)
    @ResponseResultBody
    @GetMapping(value = {"/v1//query"})
    public PageResult<AppContributionRecordView> pageableRecords() {
        return new PageResult();
    }

    @Override
    public String loginId() {
        return BaseUserInfo.getLoginId();
    }

    public static class ${entity}RateLimiterFallback implements RateLimiterFallback {

        @Override
        public Object fallback(IRateLimiter limiter) {
              throw new ApplicationException("服务繁忙，请稍后再试");
        }
    }
}
